package com.consumer.rabitmq;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;

import java.io.IOException;
import java.util.Properties;

/**
 * Created by chao on 2019/3/28.
 */

@Configuration
public class RabbitConfig {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());




    public static final String EXCHANGE_A = "my-mq-exchange_A";
    public static final String EXCHANGE_B = "my-mq-exchange_B";
    public static final String EXCHANGE_C = "my-mq-exchange_C";


    public static final String QUEUE_A = "QUEUE_A";
    public static final String QUEUE_B = "QUEUE_B";
    public static final String QUEUE_C = "QUEUE_C";

    public static final String ROUTINGKEY_A = "spring-boot-routingKey_A";
    public static final String ROUTINGKEY_B = "spring-boot-routingKey_B";
    public static final String ROUTINGKEY_C = "spring-boot-routingKey_C";


//    @Bean
//    ConnectionFactory connectionFactory() {
//        Properties properties = new Properties();
//
//        try {
//            Resource res = new ClassPathResource("rabbitmq.properties");
//            properties.load(res.getInputStream());
//        } catch (IOException e) {
//            throw new RuntimeException("Failed to load rabbitmq.properties!");
//        }
//
//        String ip = properties.getProperty("ip");
//        int port = Integer.parseInt(properties.getProperty("port"));
//        String userName = properties.getProperty("user_name");
//        String password = properties.getProperty("password");
//
//        CachingConnectionFactory connectionFactory = new CachingConnectionFactory(ip, port);
//
//        connectionFactory.setUsername(userName);
//        connectionFactory.setPassword(password);
//        connectionFactory.setVirtualHost("/");
//        connectionFactory.setChannelCacheSize(100);
//        connectionFactory.setPublisherConfirms(true); // enable confirm mode
//        //connectionFactory.getRabbitConnectionFactory().setAutomaticRecoveryEnabled(true);
//
//        return connectionFactory;
//    }
}
